﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PrototypeZGame
{
    public class Camera2D
    {
        private float m_scale;
        private Vector2 m_position;
        private World world;


        public Vector2 position
        {
            get { return m_position; }
            set { m_position = value; }
        }

        public float scale
        {
            get { return m_scale; }
            set
            {
                m_scale = value;
                if (m_scale > 1.0f) m_scale = 1.0f;
                if (m_scale < 0.1f) m_scale = 0.125f;
            }
        }



        public Camera2D(World world)
        {
            this.world = world;
            m_scale = 1.0f;
            m_position = new Vector2(0.0f);
        }
        

        public Matrix getCameraMatrix()
        {
            return Matrix.CreateTranslation(new Vector3(position.X, position.Y, 0))
                * Matrix.CreateScale(scale);
        }

        public void move(float x, float y)
        {
            m_position.X += x/scale;
            m_position.Y += y/scale;
        }

        public void centerOn(Actor actor)
        {
            m_position = actor.worldPosition;
            m_position.X += world.screenWidth / 2;
            m_position.Y += world.screenHeight / 2;
        }


    }
}
